package com.lw.yygh.order.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lw.yygh.enums.OrderStatusEnum;
import com.lw.yygh.model.order.OrderInfo;
import com.lw.yygh.model.order.OrderQueryVo;
import com.lw.yygh.model.user.UserInfo;
import com.lw.yygh.order.service.OrderService;
import com.lw.yygh.result.Result;
import com.lw.yygh.utils.AuthContextHolder;
import com.lw.yygh.utils.HttpRequestHelper;
import com.lw.yygh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {
    @Autowired
    private OrderService orderService;

    //生成订单
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result saveOrder(@PathVariable String scheduleId,
                            @PathVariable Long patientId){
        String order = orderService.saveOrder( scheduleId, patientId );
        return Result.ok(order);
    }
    //根据订单id查询订单详情
    @GetMapping("auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId) {
        OrderInfo orderInfo = orderService.getOrder(orderId);
        return Result.ok(orderInfo);
    }
    //用户订单列表（条件带分页）
    @GetMapping("/auth/{page}/{limit}")
    public Result list(@PathVariable long page,
                       @PathVariable long limit,
                       OrderQueryVo orderQueryVo, HttpServletRequest request){
        Page<OrderInfo> pageParam = new Page<>(page,limit);
        Long userId = AuthContextHolder.getUserId( request );
        orderQueryVo.setUserId( userId );
        IPage<OrderInfo> pageModel = orderService.selectPage( pageParam, orderQueryVo );
        return Result.ok( pageModel );
    }

    //获取订单状态分类
    @GetMapping("auth/getStatusList")
    public Result getStatusList() {
        return Result.ok( OrderStatusEnum.getStatusList());
    }

}
